<template>
  <div>
    <el-empty v-if="form==null||form=={}" description="暂无数据" />
    <el-form v-else ref="form" :model="form" label-width="80px" class="form">
      <el-form-item label="标题">
        <el-input v-model="form.titleName" />
      </el-form-item>
      <el-form-item label="封面">
        <el-image style="width: 100px; height: 100px" :src="form.pImg" />
      </el-form-item>
      <el-form-item v-show="form.wId!=null" label="版本">
        <el-select v-model="form.eName" placeholder="请选择活动区域">
          <el-option v-for="eItem in edition" :key="eItem.eId" :label="eItem.eName" value="eItem.eName" />
        </el-select>
      </el-form-item>
      <el-form-item v-show="form.wId!=null" label="网站名称">
        <el-input v-model="form.wName" />
      </el-form-item>
      <el-form-item v-show="form.wId!=null" label="网站链接">
        <el-input v-model="form.wLink" />
      </el-form-item>
      <el-form-item label="类别">
        <el-select v-model="form.tName" placeholder="请选择活动区域">
          <el-option v-for="tItem in tags" :key="tItem.tId" :label="tItem.tName" :value="tItem.tName" />
        </el-select>
      </el-form-item>
      <el-form-item label="时间">
        <el-date-picker v-model="form.pTime" type="datetime" placeholder="选择日期时间" />
      </el-form-item>
      <el-form-item label="文章内容">
        <div class="form_textarea" v-html="form.pDescribe" />
        <!-- <el-input v-html="form.pDescribe" type="textarea" /> -->
      </el-form-item>
      <el-form-item v-show="form.isUpload!=2">
        <!-- <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button>取消</el-button> -->
        <el-button type="success" size="mini" @click="toExamine(form.pId,2,uId)">通过</el-button>
        <el-button type="danger" size="mini" @click="toExamine(form.pId,3,uId)">不通过</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import tagApi from '@/api/tags'
import editionApi from '@/api/edition'
import postApi from '@/api/post'
import adminMesApi from '@/api/adminMes'
import { parseTime } from '@/utils/index'
export default {
  computed: mapGetters([
    'uId'
  ]),
  data() {
    return {
      form: {},
      tags: [],
      edition: [],
      adminMes: {
        message: '',
        aTime: '',
        pId: null,
        auditorId: null
      }
    }
  },
  created() {
    this.form = this.$route.params.val
    this.getTags()
    this.getEdition()
    console.log()
  },
  methods: {
    // 获取版本
    getEdition() {
      editionApi.getEdition().then(response => {
        this.edition = response.data
      })
    },
    // 获取类别
    getTags() {
      tagApi.getTags().then(response => {
        console.log(response)
        this.tags = response.data
      })
    },
    // 审核意见
    toExamine(pId, num, uId) {
      this.adminMes.aTime = parseTime(new Date(), '{y}-{m}-{d} {h}:{i}:{s}')
      this.adminMes.pId = pId
      this.adminMes.auditorId = uId
      if (num === 2) {
        this.adminMes.message = '您的文章已通过审核,现已开放浏览。'
        adminMesApi.addAdminMes(this.adminMes).then(response => {
          this.$message({
            message: response.message,
            type: 'success'
          })
        })
      } else if (num === 3) {
        this.$prompt('请输入审核意见', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(({ value }) => {
          this.adminMes.message = '您的文章审核未通过，原因是：“' + value + '”，可修改后重新上传审核。'
          adminMesApi.addAdminMes(this.adminMes).then(response => {
            this.$message({
              message: response.message,
              type: 'success'
            })
            console.log('ss')
            this.onSubmit(pId, num)
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消输入'
          })
        })
      }
    },
    onSubmit(pId, num) {
      console.log(pId)
      postApi.updateUpload(pId, num).then(response => {
        // console.log(response)
        if (response.code === 20000) {
          this.$message({
            message: response.message,
            type: 'success'
          })
          this.$router.push('/article/approval')
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.approval_operate {
  margin: 15px 0;
}
.form {
  margin: 20px;
}
.form_textarea {
  padding: 0 10px;
  border: 1px solid #c0c4cc;
  border-radius: 10px;
}
</style>
